home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / Graphic Elements 2 / Extras / GUtilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  2.6 KB  |  132 lines  |  [TEXT/MPS ]

  1. /*
  2.     GUtilities.c
  3.     
  4.     General-purpose utility routines
  5.     
  6. */
  7.  
  8. #include "GUtilities.h"
  9.  
  10. //Globals
  11. Str255        gAppName;
  12. OSType        gSignature;
  13. short        gAppResRef;
  14. Boolean        gInBackground = false;
  15.  
  16. //Are we using the new headers?
  17. #if defined(__CONDITIONALMACROS__)
  18. #define NEWHEADERS 1
  19. #else
  20. #define NEWHEADERS 0
  21. #endif
  22.  
  23. #if FORPPC
  24. extern QDGlobals    qd;
  25. #endif
  26.  
  27. Handle    GetAppIndResource(ResType theType, short index, OSErr *err)
  28. {
  29. #pragma unused (err)
  30.  
  31.     short    savedResFile;
  32.     Handle    returnHandle;
  33.     
  34.     savedResFile = CurResFile ();
  35.     UseResFile (gAppResRef);
  36.     returnHandle = Get1IndResource(theType, index);
  37.     UseResFile (savedResFile);
  38.     return (returnHandle);
  39. }
  40.  
  41. void InitSystem( short mbCount )
  42. {
  43.     short counter;
  44.     Handle    apParam;
  45.     Handle    bndlResource;
  46.     OSErr    err;
  47.     
  48.     for (counter = 0; counter < mbCount; counter++)
  49.         MoreMasters();
  50.     InitGraf(&qd.thePort);
  51.     InitFonts();
  52.     InitWindows();
  53.     TEInit();
  54.     InitMenus();
  55.     InitDialogs(0L);
  56.     DrawMenuBar();
  57.     FlushEvents(everyEvent,0L);
  58.     InitCursor();
  59.     InitAllPacks();
  60. #if NEWHEADERS
  61.     BlockMove((Ptr) LMGetCurApName(), &gAppName, 255);
  62.     gAppResRef =  LMGetCurApRefNum();
  63.     apParam = LMGetAppParmHandle();
  64. #else
  65.     GetAppParms(gAppName, &gAppResRef, &apParam);
  66. #endif
  67.     bndlResource = GetAppIndResource('BNDL', 1, &err);
  68.     if (bndlResource)
  69.         gSignature = *(OSType *) (*bndlResource);
  70.  
  71. }
  72.  
  73. Boolean LoadMenus( short mBarNum )
  74. {
  75.     Handle    menuBar;
  76.     
  77.     menuBar = GetNewMBar(mBarNum);    
  78.     if (!menuBar)
  79.         return false;
  80.     SetMenuBar(menuBar);                    /* install menus */
  81.     DisposHandle(menuBar);
  82.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* add DA names to Apple menu */
  83.     DrawMenuBar();
  84.     return true;
  85. }
  86.  
  87. void TellUser(Str255 what, short errNum)
  88. {
  89.     short        itemHit;
  90.     unsigned char    errNumStr[256];
  91.     
  92.     SetCursor(&qd.arrow);
  93.     if (errNum) 
  94.         sprintf((char *) &errNumStr, "Significant number: %d", errNum);
  95.     else
  96.         sprintf((char *) &errNumStr, "No error number to report", 0);
  97.     ParamText(what, (ConstStr255Param) c2pstr((char *) errNumStr),nil,nil);
  98.     itemHit = NoteAlert(rUserAlert, nil);
  99. }
  100.  
  101. char *C2PStrCpy(char *Cstr, Str255 Pstr)
  102. {
  103.     short i, len = strlen(Cstr);
  104.     
  105.     for(i=len; i>0; i--) {
  106.         Pstr[i] = Cstr[i-1];
  107.     }
  108.     Pstr[i] = len;
  109.     
  110.     return( (char *) Pstr );
  111. }
  112.  
  113. Boolean GetOpenFSSpec(SFTypeList *types, short nTypes, FSSpec *fileSpec)
  114. {
  115.     StandardFileReply    openReply;
  116.     
  117.     StandardGetFile(nil, nTypes, *types, &openReply);
  118.     *fileSpec = openReply.sfFile;
  119.     return(openReply.sfGood);
  120. }
  121.  
  122. Boolean GetSaveFSSpec(SFTypeList *types, FSSpec *fileSpec)
  123. {
  124.     StandardFileReply    saveReply;
  125.     
  126.     StandardPutFile((ConstStr255Param) "\pSave as:",(ConstStr255Param) "", &saveReply);
  127.     
  128.     *fileSpec = saveReply.sfFile;
  129.     return (saveReply.sfGood);
  130. }
  131.  
  132.